package org.jaaksi.customviewdemo.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import extension.dp
import kotlinx.android.synthetic.main.fragment_paintview.*
import org.jaaksi.customviewdemo.R

class PaintViewFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_paintview, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        tvEraser.setOnClickListener {
            paintView.setMode(true)
        }
        tvUndo.setOnClickListener {
            paintView.undo()
        }
        tvRedo.setOnClickListener {
            paintView.redo()
        }
        tv1.setOnClickListener {
            paintView.setMode(false)
            paintView.color = resources.getColor(R.color.purple_200)
            paintView.strokeWith = 1.dp
        }
        tv3.setOnClickListener {
            paintView.setMode(false)
            paintView.color = resources.getColor(R.color.purple_500)
            paintView.strokeWith = 5.dp
        }
        tv5.setOnClickListener {
            paintView.setMode(false)
            paintView.color = resources.getColor(R.color.teal_700)
            paintView.strokeWith = 10.dp
        }
    }
}